        var storageStore = new Ext.data.JsonStore({
			url: '/weihe/getStorage_storage',
			root: 'datas',
			sortInfo: {
    				 field: 'StorageCode'
					},
			fields : [{
						name:'StorageId',mapping:'id'
					},{
						name:'StorageCode',mapping:'code'
					},{
						name:'StorageCount',mapping:'count'
					},{
						name:'StorageName',mapping:'name'
				    },{
				    	name:'StorageOrigin',mapping:'origin'
				    },{
				    	name:'StorageSpecs',mapping:'specs'
				    },{
				    	name:'StorageUnit',mapping:'unit'
				    },{
				    	name:'StoragePrice',mapping:'price'
				    },{
				    	name:'StoragePlace',mapping:'place'
				    },{
				    	name:'StorageLocation',mapping:'location'
				    },{
				    	name:'StorageSign',mapping:'sign'
				      }],
					listeners :{ 
					   'beforeload':function(s,options) {
							var tag = 0;
							Ext.Ajax.request({
								url : '/weihe/getListJudge_storage',
								success : function(response) {
									var json = Ext.decode(response.responseText);
									if (json.deny) {
										Ext.Msg.alert('错误',json.msg);
										tag = 1;
									}
										if(tag == 1){
											return false;
										}else{
											return true;						
										}
								},
								failure : function() {
									Ext.Msg.alert('错误', '失败!');
									tag =1;
								}
							});
			   }
			}

		});
    	
    	

storages = function(){
  return{
     
	  storageGrid : function(){

		var pageToolBar = new Ext.PagingToolbar({
			pageSize : 15,
			store : storageStore,
			displayInfo : true,
			displayMsg : '当前显示{0}-{1}条记录,共{2}条记录',
		    emptyMsg : "没有记录显示!",
		    firstText : '首页',
		    prevText : '上一页',
		    nextText : '下一页',
		    lastText : '尾页',
		    beforePageText : '第',
		    afterPageText : '页,共{0}页'
		   
		});

			var whComboData = new Ext.data.SimpleStore({
				fields : ['text'],
				data : [['A'],['B'],['C'],['X'],['Y']]
			});

		var rowSelectionModel = new Ext.grid.RowSelectionModel({singleSelect : true});
		
		    InfoFormPanel = Ext.extend(Ext.form.FormPanel , {
			
			constructor:function(){
				
				 InfoFormPanel.superclass.constructor.call(this , {
						labelWidth:55,
						defaultType:"textfield",
						defaults:{anchor:"98%"},
						baseCls:"x-plain",
						items:[{
							fieldLabel : '产品编号',
							name : 'cargo.code'
						},{
							fieldLabel : '产品名称',
							name : 'cargo.name'
						},{
							fieldLabel : '仓库',
							name : 'cargo.location',
							xtype : 'combo',
							store : whComboData,
							emptyText : '请选择',
							mode : 'local',
							triggerAction : 'all',
							allowBlank:false,
							editable: false,
							displayField : 'text'
							}]
				}) ;
			},
			getValues:function(){
					return new Ext.data.Record(this.getForm().getValues()) ;
			},
			reset:function(){
				
				this.getForm().reset() ;
			}
		}) ;

		/***************************************************************************************************************************/

		InsertInfoWindow = Ext.extend(Ext.Window , {
			
			form:new  InfoFormPanel(),
			
			constructor:function(){
				
				InsertInfoWindow.superclass.constructor.call(this , {
						
						plain:true,
						
						width:300,
						
						modal:true,
						resizable: false,
						items:this.form,
						
						closeAction:"hide",
						
						buttons:[{
							text:"确 定",
							handler:this.onSubmitClick,
							scope:this
						},{
							text:"取 消",
							handler:this.onCancelClick,
							scope:this
						}]
				}) ;
				
				this.addEvents("submit") ;
			},
			
			close:function(){
				
				this.form.reset() ;
				
				this.hide() ;
			},
			
			onSubmitClick:function(){
				 var x = this.form.getValues();
				 Ext.getCmp("storageGrid").getStore().baseParams = {'flag': true,'cargo.code':x.get("cargo.code"),
					 															 'cargo.name':x.get("cargo.name"),
					 															  'cargo.location':x.get("cargo.location")
				 };
				 Ext.getCmp("storageGrid").getStore().load({params : {start : 0, limit : 15}});
				this.close() ;
			},
			onCancelClick:function(){
				this.form.reset();
				this.close() ;
			}
			
		}) ;

	   var insertWin = new InsertInfoWindow();
	   var storageGrid = new Ext.grid.GridPanel({
		   id:'storageGrid',
		   title : '库存信息表',
		   region : 'center',
		   minColumnWidth : 50,
		   tbar:[{
			  	text:"输入查询条件",
				handler:function(){
					
					insertWin.show() ;
				},
				
				scope:this
		},"-",{
		  	text:"查看全部",
			handler:function(){
			Ext.getCmp("storageGrid").getStore().baseParams = null;
			Ext.getCmp("storageGrid").getStore().baseParams = {oversea:true};
			 Ext.getCmp("storageGrid").getStore().load({params : {start : 0, limit : 15}});
			},
			
			scope:this
	}],

		   loadMask : {msg:'正在加载数据，请稍侯...'}, // 单击分页时显示,为true显示'Loading...'
		   store : storageStore,
		   columns: [
		             {header : '产品编号', dataIndex : 'StorageCode', menuDisabled : true},
		             {header : '产品名称', dataIndex : 'StorageName'},
		             {header : '规格型号', dataIndex : 'StorageSpecs', menuDisabled : true},
		             {header : '产地', dataIndex : 'StorageOrigin', menuDisabled : true},
		             {header : '单位', dataIndex : 'StorageUnit', menuDisabled : true},
		             {header : '所在仓库', dataIndex : 'StorageLocation', menuDisabled : true},
		             {header : '存放位置', dataIndex : 'StoragePlace', menuDisabled : true},
		             {header : '价格', dataIndex : 'StoragePrice', menuDisabled : true},
		             {header : '数量', dataIndex : 'StorageCount', menuDisabled : true}
        ],
           sm : rowSelectionModel,
           listeners :{ 
			   'rowclick':function(grid, rowIndex, event) {
			   var record = grid.getStore().getAt(rowIndex);
			   Ext.getCmp("storgaeForm").form.loadRecord(record);
			   Ext.getCmp("storgaeForm").buttons[0].setText('修改');
		   }
		},
		  viewConfig : {
		     forceFit : false
		  },
		  bbar : pageToolBar
});
		return storageGrid;
	},
	storageForm : function(){

		function progressConsole() {
			//验证合法后使用加载进度条
		    Ext.MessageBox.show({
			   title: '请稍等',
			   msg: '正在处理...',
			   progressText: '',
			   width:300,
			   progress:true,
			   closable:false
			});
			//控制进度速度
			var progressConsole = function(v){
				 return function(){
						var i = v/10;
						Ext.MessageBox.updateProgress(i, i*100+'%');
			     };
			};
			for(var i = 1; i <= 10; i++){
				setTimeout(progressConsole(i), i*150);
			}
		};


		var button_add = new Ext.Button({
			text : '添加',
			handler : function() {

					progressConsole();
				if(storageForm.form.isValid()){ 	
					if (storageForm.form.findField("cargo.id").getValue() == "") {
						storageForm.form.submit({
						  url : '/weihe/addStorage_storage',
						   success : function(form, action) {
							 if (action.result.deny) {
									 Ext.Msg.alert('错误', action.result.msg);
							 }else{
								Ext.Msg.alert('消息', action.result.msg, function() {
									storageForm.form.reset();
									   Ext.getCmp("storageGrid").getStore().reload();
									
								})
							  }
						    }
					    })
					}else {
						storageForm.form.submit({
							  url : '/weihe/updateStorage_storage',
							   success : function(form, action) {
								 if (action.result.deny) {
									 Ext.Msg.alert('错误', action.result.msg);
								  }else{
									Ext.Msg.alert('消息', action.result.msg, function() {
										storageForm.form.reset();
										Ext.getCmp("storageGrid").getStore().reload();
										storageForm.buttons[0].setText('添加');
										
									})
								  }
							    }
						    })

				
						
					}
			}else{
				Ext.Msg.alert('提示','请输入相关内容');
			}
				}
		
			
		});

	var button_clear = new Ext.Button({
		id : 'button_clear',
		text : '清空',
		handler : function() {
			storageForm.form.reset();
			storageForm.buttons[0].setText('添加');
		}
	});

	var button_del = new Ext.Button({
		text : '删除',
		handler : function() {
			var id = storageForm.form.findField('cargo.id').getValue();
			if (id == '') {
				Ext.Msg.alert('提示', '请选择需要删除的信息!');
			} else {
				progressConsole();
				Ext.Ajax.request({
					url : '/weihe/deleteStorage_storage',
					success : function(response) {
						var json = Ext.decode(response.responseText);
						if (json.success) {
						  if (json.deny) {
									Ext.Msg.alert('错误',json.msg);
									storageForm.form.reset();
								    storageForm.buttons[0].setText('添加');
						  }else{
							Ext.Msg.alert('消息', json.msg, function() {
								Ext.getCmp("storageGrid").getStore().load({params : {start : 0, limit : 15}});
								storageForm.form.reset();
								storageForm.buttons[0].setText('添加');
							});
						  }
						}else{
							Ext.Msg.alert('消息', json.msg);
							storageForm.form.reset();
							storageForm.buttons[0].setText('添加');
						}
					},
					failure : function() {
						Ext.Msg.alert('错误', '删除失败!');
					},
					params : 'cargo.id=' + id
				});
			}
		}
	});
	
	var locationComboData = new Ext.data.SimpleStore({
		fields : ['text'],
		data : [['A'],['B'],['C']]
	});
	

	var  storageForm = new Ext.form.FormPanel({
		id : 'storgaeForm',
		title : '库存信息',
		frame : true,
		width : 300,
		region : 'east',
		autoScroll : true,
		labelAlign : 'right',
		labelWidth : 60,
		defaultType : 'textfield',
			defaults : {
			width : 200
		},
		items : [{  // Ext.form.Hidden
			id:'StorageId',
			xtype : 'hidden',  // 隐藏的表单
			name : 'cargo.id'
		},{  
			id:'StorageSign',
			xtype : 'hidden',  // 隐藏的表单
			name : 'cargo.sign',
			value: 'on'
		},{
			id:'StorageCode',
			fieldLabel : '产品编号',
			name : 'cargo.code',
			allowBlank:false,
			blankText:'请输入产品编号',
			regex : /^\d{6}$/,
		    regexText:'请输入6位数字产品编号'
		},{
			id:'StorageName',
			fieldLabel : '产品名称',
			allowBlank:false,
			blankText:'请输入产品名称',
			name : 'cargo.name'
		},{
			id:'StorageSpecs',
			fieldLabel : '规格型号',
			name : 'cargo.specs',
			allowBlank:false,
			blankText:'请输入规格型号'
		},{
			id:'StorageOrigin',
			fieldLabel : '产地',
			name : 'cargo.origin'
		},{
			id:'StorageUnit',
			fieldLabel : '单位',
			allowBlank:false,
			name : 'cargo.unit',
			blankText:'请输入单位'
		},{
			id:'StorageLocation',
			fieldLabel : '存放仓库',
			name : 'cargo.location',
			xtype : 'combo',
			store : locationComboData,
			emptyText : '请选择',
			mode : 'local',
			triggerAction : 'all',
			editable: false,
			displayField : 'text'
		},{
			id:'StoragePlace',
			fieldLabel : '存放位置',
			name : 'cargo.place',
			allowBlank:false,
			blankText:'请输入存放位置'
		},{
			id:'StoragePrice',
			fieldLabel : '价格',
			name : 'cargo.price',
			allowBlank:false,
			blankText:'请输入价格',
			regex : /^\d+(\.\d+)?$/,
		    regexText:'请输入有效的价格' 
		},{
			id:'StorageCount',
			fieldLabel : '数量',
			name : 'cargo.count',
			allowBlank:false,
			blankText:'请输入数量',
			regex : /^[0-9]\d*$/,
		    regexText:'请输入有效的数量'
		}],
		buttons : [button_add,button_clear,button_del]
	});
		return  storageForm;
	}
  }
}();








